package net.jonbuck.tassoo.chart.ui.data;


import net.jonbuck.tassoo.model.Container;
import net.jonbuck.tassoo.model.Status;
import net.jonbuck.tassoo.model.Statuses;
import net.jonbuck.tassoo.persistence.dao.TassooDao;
import net.jonbuck.tassoo.persistence.dao.TassooDaoImpl;
import net.jonbuck.tassoo.persistence.dao.util.TassooStatisticsHelperUtil;

/**
 * 
 * 
 * @since 1.0.0
 */
public class TaskStatusDataSet implements IDataSet {

	private Container container;

	private TassooDao tassooDao = TassooDaoImpl.getInstance();

	/**
	 * <p>
	 * <b>Creates a new <code>TaskStatusDataSet</code> using the container being
	 * passed in.</b>
	 * </p>
	 * 
	 * @param container
	 */
	public TaskStatusDataSet(Container container) {
		super();
		this.container = container;
	}

	/**
	 * @return the container
	 */
	public Container getContainer() {
		return container;
	}

	/**
	 * 
	 */
	public Object getXseries() {
		if (tassooDao.isLoaded() && container != null) {
			int count = 0;
			Statuses statuses = tassooDao.getStatuses();
			String[] statusValues = new String[statuses.getStatus().size()];
			for (Status status : statuses.getStatus()) {
				statusValues[count] = status.getValue();
				count++;
			}
			return statusValues;
		}
		return null;
	}

	/**
	 * 
	 */
	public Object getYSeries() {
		if (tassooDao.isLoaded() && container != null) {
			int count = 0;
			Statuses statuses = tassooDao.getStatuses();
			double[] statusNumbers = new double[statuses.getStatus().size()];
			for (Status status : statuses.getStatus()) {
				statusNumbers[count] = TassooStatisticsHelperUtil.getTaskNumberByStatus(tassooDao, container, status.getValue());
				count++;
			}
			return statusNumbers;
		}
		return null;
	}

	/**
	 * @param container the container to set
	 */
	public void setContainer(Container container) {
		this.container = container;
	}

}
